package searchstring;
import java.io.UnsupportedEncodingException;




public class StringBuscaIEEExploreBuilder extends AbstractStrategyStringBuscaBuilder{
	private static StringBuscaIEEExploreBuilder instance;

	private static SearchCriteria searchCriteria;
	
	private StringBuscaIEEExploreBuilder() {

	}

	/**
	 * This method returns the single instance of the class instance
	 * 
	 * @return {@link StringBuscaIEEExploreBuilder}
	 */
	public static StringBuscaIEEExploreBuilder getInstance() {
		if (StringBuscaIEEExploreBuilder.instance == null) {
			StringBuscaIEEExploreBuilder.instance = new StringBuscaIEEExploreBuilder();
			
			String searchMode = "Search_All";
			//String searchMode = "Search_All_Text";
			
			StringBuscaIEEExploreBuilder.searchCriteria = new SearchCriteria("2003", "2013", searchMode, false);
		}
		return StringBuscaIEEExploreBuilder.instance;
	}

	public String getWebSource() {
		return "ieeexplore.ieee.org";
	}
	
	/**
	 * 
	 * 
	 * @param search_String
	 * @return
	 */
	public String getURL(String search_String){ 

		String search_String_formatted = null;
		try {
			search_String_formatted = java.net.URLEncoder.encode(search_String, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		SearchCriteria searchCriteria = StringBuscaIEEExploreBuilder.searchCriteria;
		
		String subscribedField =  searchCriteria.isSubscribed() ? "%26subscribed%3D"+searchCriteria.isSubscribed() : "";
		
		return "http://ieeexplore.ieee.org/search/searchresult.jsp?matchBoolean%3Dtrue" +
				subscribedField+
				"%26searchField%3D"+searchCriteria.getSearchMode()+
				"%26queryText%3D"+search_String_formatted+
				"&addRange="+searchCriteria.getMinYear()+"_"+searchCriteria.getMaxYear()+"_Publication_Year" +
						"&pageNumber=1&resultAction=REFINE";
		
		
	}

}
